home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 1 / Amiga Tools.iso / egs-tools / egs_dev-disk / egsdemos / egsexamples / menu / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-06  |  2.9 KB  |  170 lines

  1. /*
  2. *
  3. *  $ FILE     : main.c
  4. *  $ VERSION  : 1
  5. *  $ REVISION : 2
  6. *  $ DATE     : 08-Dec-93 18:21
  7. *  $
  8. *  $ Author   : mvk
  9. *  $
  10. *
  11. *
  12. **  This demo shows the easy way to create
  13. **  EGS-menus. See InitMenu.c for the menu stuff.
  14. **  The other routines are for OpenLibs, Event
  15. **  and error handling.
  16. **
  17. **  In these files you will find some useful routines
  18. **  for Open / Close libraries and error handling.
  19. **
  20. **  (c) by VIONA-Development
  21. **
  22. */
  23.  
  24. #include "includes.c"
  25. #include "Global.h"
  26. #include "Eventloop.c"
  27. #include "InitMenu.c"
  28.  
  29. BOOL            InitLibraries(struct OpenStructTyp *);
  30. void            CloseLibraries(struct OpenStructTyp *);
  31.  
  32. /*
  33. **  Opens the libs form the OpenStructTyp
  34. **  (see global.h)
  35. **
  36. */
  37.  
  38. BOOL
  39. InitLibraries(struct OpenStructTyp *OS)
  40. {
  41.     struct OpenStructTyp *p = &OS[0];
  42.  
  43.     while (p->Var != NULL)
  44.     {
  45.     if ((*(p->Var) = (ULONG) OpenLibrary(p->Name, p->Version)) == NULL)
  46.     {
  47.         printf(" Can't open %s version %d", p->Name, p->Version);
  48.         return FALSE;
  49.     }
  50.     else
  51.     {
  52.         p++;
  53.     }
  54.     }
  55.     return TRUE;
  56. }
  57.  
  58.  
  59. /*
  60. ** Close the Libs from the OpenStructTyp
  61. **
  62. */
  63.  
  64. void
  65. CloseLibraries(struct OpenStructTyp *OS)
  66. {
  67.     struct OpenStructTyp *p = &OS[0];
  68.  
  69.     while (p->Name != NULL)
  70.     {
  71.     CloseLibrary((void *) (*(p->Var)));
  72.     *(p->Var) = NULL;
  73.     p++;
  74.     }
  75. }
  76.  
  77. /*
  78. ** This routine is for Errorhandling.
  79. ** It close all open thinks form the
  80. ** program.
  81. **
  82. */
  83. void
  84. myError(char   *string)
  85. {
  86.     if (string != NULL)
  87.     {
  88.     if (EGSRequestBase == NULL)
  89.     {
  90.         printf("%s\n", string);
  91.     }
  92.     else
  93.     {
  94.         ErrorReq = (ER_SimpleReqPtr) ER_CreateSimpleReq(NULL,
  95.                         (char *) string, (char *) "OK");
  96.         /*
  97.         **  Open Requester in the middle of the Screen,
  98.         **
  99.         **  if you could !?
  100.         */
  101.  
  102.         ErrorReq->Req.Nw->Flags |= EI_WINDOWCENTER;
  103.  
  104.         ER_DoRequest(&(ErrorReq->Req));
  105.     }
  106.     }
  107.     if (Window)
  108.     {
  109.     ErrorReq = ER_CreateSimpleReq(NULL,
  110.                    "Hello world !|This is a Requester !", "OK");
  111.  
  112.     ErrorReq->Req.Nw->Flags |= EI_WINDOWCENTER;
  113.     ER_DoRequest(&(ErrorReq->Req));
  114.     }
  115.     if (Window)
  116.     EI_CloseWindow(Window);
  117.  
  118.     if (Menu)
  119.     EI_FreeMenu(Menu);
  120.  
  121.     if (FontforMenu)
  122.     EG_CloseFont(FontforMenu);
  123.  
  124.     if (ErrorReq)
  125.     ER_DeleteRequest(&(ErrorReq->Req));
  126.  
  127.     CloseLibraries(OpenStruct);
  128.     exit(0);
  129. }
  130.  
  131.  
  132. int
  133. main(int argc, char *argv[])
  134. {
  135.     if (argc == 2 && strcmp("?", argv[1]) == 0)
  136.     {
  137.     printf("Aufruf: %s\n  Markus van Kempen 12 Nov 1992", argv[0]);
  138.     }
  139.     else
  140.     {
  141.     if (InitLibraries(OpenStruct) == FALSE)
  142.         myError("Can't OpenLibrary");
  143.  
  144.     FontforMenu = (EG_EFontPtr) EG_OpenFont((struct TextAttr *) & FontStr);
  145.  
  146.     if (FontforMenu == NULL)
  147.         myError("Could not open font");
  148.  
  149.     Menu = InitMenu(FontforMenu);
  150.  
  151.     if (Menu == NULL)
  152.         myError("Could not build menu");
  153.  
  154.     newwin.Menu = Menu;
  155.  
  156.     Window = (EI_WindowPtr) EI_OpenWindow((struct EI_NewWindow *) & newwin);
  157.  
  158.     if (Window)
  159.     {
  160.         HandleEvents(Window);
  161.     }
  162.     else
  163.     {
  164.         myError("Could not open window");
  165.     }
  166.     }
  167.     myError(NULL);
  168. }
  169.  
  170.